/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Giaodien;

import Lop.OConnection;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class fMain extends javax.swing.JFrame {

    /**
     * Creates new form fMain
     */
    public static OConnection cnn;
    
    public fMain() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        mDanhMuc = new javax.swing.JMenu();
        mNen = new javax.swing.JMenuItem();
        mNhomNen = new javax.swing.JMenuItem();
        mKhuTDC = new javax.swing.JMenuItem();
        mCQQL = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mQuanLy = new javax.swing.JMenuItem();
        mThongKe = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        desktopPane.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                desktopPaneComponentShown(evt);
            }
        });

        menuBar.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        fileMenu.setMnemonic('f');
        fileMenu.setText("Hệ thống");
        fileMenu.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        openMenuItem.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        openMenuItem.setMnemonic('o');
        openMenuItem.setText("Kết nối CSDL");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);
        openMenuItem.getAccessibleContext().setAccessibleName("KetnoiCSDL");

        exitMenuItem.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Thoát");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);
        fileMenu.getAccessibleContext().setAccessibleName("HeThong");

        mDanhMuc.setText("Danh mục");
        mDanhMuc.setToolTipText("");
        mDanhMuc.setActionCommand("mDanhMuc");
        mDanhMuc.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        mNen.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        mNen.setText("Nền");
        mNen.setActionCommand("mNen");
        mNen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mNenActionPerformed(evt);
            }
        });
        mDanhMuc.add(mNen);
        mNen.getAccessibleContext().setAccessibleName("mNen");

        mNhomNen.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        mNhomNen.setText("Nhóm nền");
        mNhomNen.setActionCommand("mNhomNen");
        mNhomNen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mNhomNenActionPerformed(evt);
            }
        });
        mDanhMuc.add(mNhomNen);
        mNhomNen.getAccessibleContext().setAccessibleName("mNhomNen");

        mKhuTDC.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        mKhuTDC.setText("Khu TĐC");
        mKhuTDC.setActionCommand("mKhuTDC");
        mKhuTDC.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mKhuTDCMouseClicked(evt);
            }
        });
        mKhuTDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mKhuTDCActionPerformed(evt);
            }
        });
        mDanhMuc.add(mKhuTDC);
        mKhuTDC.getAccessibleContext().setAccessibleName("mKhuTDC");

        mCQQL.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        mCQQL.setText("Cơ quan quản lý");
        mCQQL.setActionCommand("mCQQL");
        mCQQL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mCQQLActionPerformed(evt);
            }
        });
        mDanhMuc.add(mCQQL);
        mCQQL.getAccessibleContext().setAccessibleName("mCQQL");

        mDanhMuc.add(jSeparator1);

        mQuanLy.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        mQuanLy.setText("Phân công quản lý");
        mQuanLy.setActionCommand("mQuanLy");
        mDanhMuc.add(mQuanLy);
        mQuanLy.getAccessibleContext().setAccessibleName("mQuanLy");

        menuBar.add(mDanhMuc);
        mDanhMuc.getAccessibleContext().setAccessibleName("mDanhMuc");

        mThongKe.setText("Thống kê");
        mThongKe.setToolTipText("");
        mThongKe.setActionCommand("mThongKe");
        mThongKe.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        menuBar.add(mThongKe);
        mThongKe.getAccessibleContext().setAccessibleName("mThongKe");

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 962, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame fChild: this.desktopPane.getAllFrames()){
            fChild.dispose();
        }
        fCauhinh fcauhinh = new fCauhinh();
        fcauhinh.setLocation(this.getWidth()/2 - fcauhinh.getWidth()/2, (this.getHeight()-20)/2 - (fcauhinh.getHeight()/2 - 20));
        desktopPane.add(fcauhinh);
        fcauhinh.setVisible(true);
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void desktopPaneComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_desktopPaneComponentShown
        // TODO add your handling code here:
        
    }//GEN-LAST:event_desktopPaneComponentShown

    private void mCQQLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mCQQLActionPerformed
       gCQQL cqql = new gCQQL();
       cqql.setLocation(this.getWidth()/2 - cqql.getWidth()/2, (this.getHeight()-20)/2 - (cqql.getHeight()/2 - 20));
       desktopPane.add(cqql);
       cqql.setVisible(true);
    }//GEN-LAST:event_mCQQLActionPerformed

    private void mNhomNenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mNhomNenActionPerformed
        // TODO add your handling code here:
        for(JInternalFrame fChild: this.desktopPane.getAllFrames()){
            fChild.dispose();
        }
        gNhomnen gnhomnen = new gNhomnen();
        gnhomnen.setLocation(this.getWidth()/2 - gnhomnen.getWidth()/2, (this.getHeight()-20)/2 - (gnhomnen.getHeight()/2 - 20));
        desktopPane.add(gnhomnen);
        gnhomnen.setVisible(true);
    }//GEN-LAST:event_mNhomNenActionPerformed


    private void mKhuTDCMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mKhuTDCMouseClicked
        // TODO add your handling code here:
        
    }//GEN-LAST:event_mKhuTDCMouseClicked

    private void mKhuTDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mKhuTDCActionPerformed
        // TODO add your handling code here:
        gKHU_TDC khutdc = new gKHU_TDC();
        khutdc.setLocation(this.getWidth()/2 - khutdc.getWidth()/2, (this.getHeight()-20)/2 - (khutdc.getHeight()/2 - 20));
        desktopPane.add(khutdc);
        khutdc.setVisible(true);
    }//GEN-LAST:event_mKhuTDCActionPerformed


    private void mNenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mNenActionPerformed
        // TODO add your handling code here:
        
        gNen1 nen = new gNen1();
        nen.setLocation(this.getWidth()/2 - nen.getWidth()/2, (this.getHeight()-20)/2 - (nen.getHeight()/2 - 20));
        
        desktopPane.add(nen);
        nen.setVisible(true);
    }//GEN-LAST:event_mNenActionPerformed


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(fMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(fMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(fMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(fMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                fMain fmain = new fMain();
                fmain.pack();
                fmain.setLocationRelativeTo(null);
                fmain.setVisible(true);
                try{
                    cnn = new OConnection();
                    cnn.XMLRead();
                    if((!cnn.getType().equals("") &&
                        !cnn.getServerName().equals("") &&
                        !cnn.getServiceName().equals("") &&
                        !cnn.getUserName().equals("") &&
                        !cnn.getPort().equals("")) || (!cnn.getType().equals("") && !cnn.getFileName().equals(""))){
                        if(cnn.createConnection().isValid(0)){
                            mDanhMuc.setEnabled(true);
                            mThongKe.setEnabled(true);
                            fmain.setTitle("Quan ly khu TDC - Oracle");
                        }
                        else{
                            mDanhMuc.setEnabled(false);
                            mThongKe.setEnabled(false);
                            fmain.setTitle("Quan ly khu TDC");
                        }
                    }
                    else{
                        mDanhMuc.setEnabled(false);
                        mThongKe.setEnabled(false);
                        fmain.setTitle("Quan ly khu TDC");
                    }
                }
                catch(Exception e){
                    mDanhMuc.setEnabled(false);
                    mThongKe.setEnabled(false);
                    fmain.setTitle("Quan ly khu TDC");
                    JOptionPane.showMessageDialog(null, e);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuItem mCQQL;
    private static javax.swing.JMenu mDanhMuc;
    private javax.swing.JMenuItem mKhuTDC;
    private javax.swing.JMenuItem mNen;
    private javax.swing.JMenuItem mNhomNen;
    private javax.swing.JMenuItem mQuanLy;
    private static javax.swing.JMenu mThongKe;
    private static javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    // End of variables declaration//GEN-END:variables

}
